package com.ustadzmenjawab.server;

import java.util.Hashtable;

import org.apache.lucene.index.FieldInvertState;
import org.apache.lucene.search.DefaultSimilarity;

public class NormalizedSimilarity extends DefaultSimilarity {
	protected DefaultSimilarity normalizedSimilarity;
	protected Hashtable<String,Float> maxScoreField;
	
	public NormalizedSimilarity(Hashtable<String,Float> inputScoreScale){
		normalizedSimilarity = new DefaultSimilarity();
		this.maxScoreField = inputScoreScale;
	}
	@Override
	public float computeNorm(String field,FieldInvertState state){
		if(maxScoreField != null && maxScoreField.get(field) != null && maxScoreField.get(field) > 0.0){
			return  super.computeNorm(field, state)/ maxScoreField.get(field) ;
		}
		return super.computeNorm(field, state);
	}
	
	
}
